package com.house.framework.utils;

/**
 * <p>
 * Gis 工具类
 * </p>
 *
 * @author yangh
 * @since 2022-12-18
 */

public class GisUtil {
    private static final double EARTH_RADIUS = 6378.5D;

    public static final double DEG2RAD = 0.017453292519943295D;

    public static long geoDistance(GeoPoint point1, GeoPoint point2) {
        double alpha = getInnerProduct(point1, point2);
        if (alpha >= 1.0D)
            return 0;
        if (alpha <= -1.0D)
            return 20038648;
        return Math.round(Math.acos(alpha) * EARTH_RADIUS * 1000);
    }

    private static double getInnerProduct(GeoPoint point1, GeoPoint point2) {
        return  Math.sin(point1.getLat() * 0.017453292519943295D) * Math.sin(point2.getLat() * 0.017453292519943295D) +
                Math.cos(point1.getLat() * 0.017453292519943295D) * Math.cos(point2.getLat() * 0.017453292519943295D) *
                        Math.cos(point1.getLng() * 0.017453292519943295D - point2.getLng() * 0.017453292519943295D);
    }

    public static class GeoPoint {
        private double lng = 0.0D;

        private double lat = 0.0D;

        public GeoPoint(double lng, double lat) {
            this.lng = lng;
            this.lat = lat;
        }

        public double getLng() {
            return this.lng;
        }

        public void setLng(double lng) {
            this.lng = lng;
        }

        public double getLat() {
            return this.lat;
        }

        public void setLat(double lat) {
            this.lat = lat;
        }
    }


    public static void main(String[] args) {
        GeoPoint p1 = new GeoPoint(116.400694,39.98324);
        GeoPoint p2 = new GeoPoint(116.413845,39.98324);
        System.out.println(geoDistance(p1,p2));
    }

    public final class MapType {
        public static final String BAIDU = "baidu";

        public static final String BAIDUEN = "baiduEn";

        public static final String GAODE = "gaode";

        public static final String TENCENT = "tencent";

        public static final String GOOGLE = "google";

        public static final String GOOGLECN = "googleCN";

        public static final String HERE = "here";
    }

    public final class CoordinateType {
        public static final String WGS84 = "WGS84";

        public static final String GCJ02 = "GCJ02";

        public static final String BD09 = "BD09";
    }


}

